package com.kfm.pm;


import java.util.Arrays;
import java.util.Scanner;

public class Exec01 {

    public static void main(String[] args) {
        // 给定一个整数数组，输入一个值 n, 输出去掉数组中第 n 大的数后的数组
        int[] nums = {1, 3, 5, -1, 4, 7};
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除第几大的数：");
        int n = sc.nextInt();
        int[] newArr = clear(nums, n);
        System.out.println(Arrays.toString(newArr));
    }

    public static int[] clear(int[] arr, int n) {
        // 冒泡排序
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] < arr[j + 1]) {
                    arr[j + 1] = arr[j] ^ arr[j + 1];
                    arr[j] = arr[j] ^ arr[j + 1];
                    arr[j + 1] = arr[j] ^ arr[j + 1];
                }
            }
        }
        // 4, 3, 2, 1  2  1
        int[] newArr = new int[arr.length - 1];
        System.arraycopy(arr, 0, newArr, 0, n - 1);
        System.arraycopy(arr, n, newArr, n - 1, arr.length - n);
        return newArr;
    }
}
